package com.xnx.bincker.leader.controller;

import com.xnx.bincker.leader.controller.admin.AdminController;
import com.xnx.bincker.leader.utils.RestLinkUtils;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

import static com.xnx.bincker.leader.utils.RestLinkUtils.*;

/**
 * 首页控制器
 */
@RestController
@Log4j2
public class IndexController {
    private final RestLinkUtils restLinkUtils;

    public IndexController(RestLinkUtils restLinkUtils) {
        this.restLinkUtils = restLinkUtils;
    }

    /**
     * 根路径
     */
	@RequestMapping("/")
	@ResponseBody
	public Map<String, Object> index(HttpServletRequest request) throws NoSuchMethodException {
	    Map<String, Object> result = new HashMap<>();
	    result.put("baseURI", request.getContextPath());
        result.putAll(links(
                new Link("login", "POST", "/authentication"),
                restLinkUtils.getLink("adminApis", AdminController.class.getMethod("index"))
        ));
        return result;
    }
}
